package com.yhally.seata.storage.controller;

import com.yhally.seata.common.domain.CommonResult;
import com.yhally.seata.storage.service.StorageService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
/**
 *
 * @author wangyu
 * @version 1.0
 * @date 2022/5/6 23:00
 */
@RestController
@RequestMapping("/storage")
public class StorageController {

    @Resource
    private StorageService storageService;

    /**
     * <p>描述: AT模式下扣减库存
     * <p>开发者: wangyu
     * <p>时间: 2022/5/8 22:27
     *
     * @param productId
     * @param count
     * @return CommonResult
     */
    @PostMapping(value = "/decrease")
    public CommonResult decrease(@RequestParam("productId") Long productId,
                                 @RequestParam("count") Integer count) {
        storageService.decrease(productId,count);
        return new CommonResult(200, "扣减库存成功");
    }

    /**
     * <p>描述: TCC 模式下扣减库存
     * <p>开发者: wangyu
     * <p>时间: 2022/5/8 22:27
     *
     * @param productId
     * @param count
     * @return CommonResult
     */
    @PostMapping(value = "/decreaseByTcc")
    public CommonResult decreaseByTcc(@RequestParam("productId") Long productId,
                                 @RequestParam("count") Integer count) {
        storageService.decreaseByTcc(productId,count);
        return new CommonResult(200, "扣减库存成功");
    }
}

